package de.jabc.sib.bio.ebi;

import de.jabc.adapter.bio.ebi.Branches;
import de.jabc.adapter.bio.ebi.LightweightServiceAdapter;
import de.jabc.adapter.bio.ebi.ServiceAdapter;
import de.metaframe.jabc.framework.execution.ExecutionEnvironment;
import de.metaframe.jabc.framework.sib.annotation.SIBClass;
import de.metaframe.jabc.framework.sib.annotation.SIBStatus;
import de.metaframe.jabc.framework.sib.parameter.ContextExpression;
import de.metaframe.jabc.framework.sib.parameter.ContextKey;
import de.metaframe.jabc.sib.ServiceAdapterDescriptor;

/**
 * Calls the EBI's EMBOSS Pepstats service.
 * 
 * EMBOSS pepstats calculates statistics for a protein such as molecular weight
 * and isoelectric point
 * 
 * @author plevko@mail.muni.cz
 */
@SIBClass("ebi-sibs/Pepstats")
@SIBStatus("IMPLEMENTED")
public class Pepstats extends AbstractSIB {

	/* Branches */
	public static final String[] BRANCHES = { Branches.DEFAULT, Branches.ERROR };

	/* Parameters */
	public ContextExpression Email = new ContextExpression("", String.class,
			false);
	public ContextExpression Title = new ContextExpression("", String.class,
			false);
	public ContextExpression Termini = new ContextExpression("", String.class,
			false);
	public ContextExpression Mono = new ContextExpression("", String.class,
			false);	
	public ContextExpression Sequence = new ContextExpression("", String.class,
			false);
	public ContextKey resultOut = new ContextKey("resultOut",
			ContextKey.Scope.LOCAL, true);

	/**
	 * @see de.metaframe.jabc.sib.CodeGeneratorBlock#execute(ExecutionEnvironment)
	 */
	public String execute(ExecutionEnvironment environment) {
		try {
			return ServiceAdapter.callPepstats(environment, this.Email,
					this.Title, this.Termini, this.Mono, this.Sequence,
					this.resultOut);
		} catch (NoClassDefFoundError e) {
			return Branches.ERROR;
		}
	}

	/**
	 * @see de.metaframe.jabc.sib.Generatable#generate()
	 */
	public ServiceAdapterDescriptor generate() {
		return new ServiceAdapterDescriptor(
				LightweightServiceAdapter.class.getName(), "callPepstats",
				"Email", "Title", "Termini", "Mono", "Sequence", "resultOut");
	}

}
